﻿using Cxuu.Models;
using Cxuu.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;

namespace Cxuu.Web.Home
{
    public class Base : Controller
    {
        public Base() { }

        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            EditConfigSiteInfo siteConfig = await SiteConfigAsync(context);
            ViewBag.SiteConfig = siteConfig;
            await base.OnActionExecutionAsync(context, next);
        }


        public async Task<EditConfigSiteInfo> SiteConfigAsync(ActionExecutingContext context)
        {
            ConfigService _configService = context.HttpContext.RequestServices.GetService<ConfigService>();
            EditConfigSiteInfo config = await _configService.GetByNameAsync();
            //EditConfigSiteInfo configData = JsonConvert.DeserializeObject<EditConfigSiteInfo>(config.Data);
            return config;
        }
    }
}
